package java01_type;

import common.bean.OuterClass;
import org.junit.jupiter.api.Test;

/**
 * https://blog.csdn.net/2301_79201049/article/details/142285915
 * https://blog.csdn.net/2302_80198073/article/details/139832937
 */
public class Test08_InnerClass {
    /**
     * 在实例化非静态内部类之前,必选先创建一个外部类对象
     */
    @Test
    void test_inner_class() {

        //报错，不能直接调用内部类
        //OuterClass.InnerClass inner = new OuterClass.InnerClass(35);

        OuterClass outer = new OuterClass();
        OuterClass.InnerClass inner = outer.new InnerClass(35);
        System.out.println(inner);
    }

    @Test
    void test_outer_class() {
        OuterClass outer = new OuterClass();
        outer.setAge(40);
        outer.printInner();
    }

    /**
     * 静态内部类
     */
    @Test
    void test_static_inner() {
        OuterClass.StaticInnerClass staticInner = new OuterClass.StaticInnerClass();
        staticInner.setInnerField(36);
        staticInner.innerMethod();
    }
}
